import React, { lazy, Suspense } from 'react';
import {Route, useRouteMatch, Switch, Router, HashRouter} from 'react-router-dom';
import Loader from '@iso/components/utility/loader';
import {PRIVATE_ROUTE} from "../../route.constants";

import { createHashHistory} from "history";

const routes = [
	{
		path: '',
		component: lazy(() => import('@iso/containers/Pages/Dashboard/Dashboard')),
		exact: true,
	},{
		path: PRIVATE_ROUTE.MENU_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/base/Menu')),
		exact: true
	},{
		path: PRIVATE_ROUTE.FUNCTION_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/base/Function')),
		exact: true
	},{
		path: PRIVATE_ROUTE.ORGANIZATION_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/base/Organization')),
		exact: true
	},{
		path: PRIVATE_ROUTE.ROLE_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/base/Role')),
		exact: true
	},{
		path: PRIVATE_ROUTE.USER_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/base/User')),
		exact: true
	},{
		path: PRIVATE_ROUTE.ID_GENERATOR_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/configuration/IdGenerator')),
		exact: true
	},{
		path: PRIVATE_ROUTE.SEQUENCE_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/configuration/Sequence')),
		exact: true
	},{
		path: PRIVATE_ROUTE.DATA_DICTIONARY_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/configuration/DataDictionary')),
		exact: true
	},{
		path: PRIVATE_ROUTE.OTHER_SETTINGS,
		component: lazy(() => import('@iso/containers/Pages/user/Settings')),
		exact: true
	},{
		path: PRIVATE_ROUTE.OTHER_PROFILE,
		component: lazy(() => import('@iso/containers/Pages/user/Profile')),
		exact: true
	},{
		path: PRIVATE_ROUTE.NOTICE_CATEGORY,
		component: lazy(() => import('@iso/containers/Pages/notice/NoticeCategory')),
		exact: true
	},{
		path: PRIVATE_ROUTE.NOTICE_MANAGE,
		component: lazy(() => import('@iso/containers/Pages/notice/Notice')),
		exact: true
	},{
		path: PRIVATE_ROUTE.NOTICE_MINE,
		component: lazy(() => import('@iso/containers/Pages/notice/NoticeMine')),
		exact: true
	},{
		path: PRIVATE_ROUTE.NOTICE_ADD,
		component: lazy(() => import('@iso/containers/Pages/notice/NoticeAdd')),
		exact: true
	},{
		path: PRIVATE_ROUTE.NOTICE_EDIT,
		component: lazy(() => import('@iso/containers/Pages/notice/NoticeEdit')),
		exact: true
	},{
		path: PRIVATE_ROUTE.NOTICE_VIEW,
		component: lazy(() => import('@iso/containers/Pages/notice/NoticeView')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_OVERVIEW,
		component: lazy(() => import('@iso/containers/Pages/Oa/Work/ScheduleOverview')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_MINE,
		component: lazy(() => import('@iso/containers/Pages/Oa/Work/MySchedule')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_USER,
		component: lazy(() => import('@iso/containers/Pages/Oa/Work/UserSchedule')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_USER_TO_ME,
		component: lazy(() => import('@iso/containers/Pages/Oa/Work/UserScheduleToMe')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_USER_DETAIL,
		component:  lazy(() => import('@iso/containers/Pages/Oa/Work/UserScheduleDetail')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_NOTE_CATEGORY,
		component:  lazy(() => import('@iso/containers/Pages/Oa/Note/NoteCategory')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_NOTE_ADD,
		component:  lazy(() => import('@iso/containers/Pages/Oa/Note/NoteAdd')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_NOTE_MINE,
		component:  lazy(() => import('@iso/containers/Pages/Oa/Note/NoteMine')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_NOTE_EDIT,
		component:  lazy(() => import('@iso/containers/Pages/Oa/Note/NoteEdit')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_REPORT_MINE,
		component: lazy(() => import('@iso/containers/Pages/Oa/Work/MyReport')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_REPORT_USER,
		component: lazy(() => import('@iso/containers/Pages/Oa/Work/UserReport')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_REPORT_USER_TO_ME,
		component: lazy(() => import('@iso/containers/Pages/Oa/Work/UserReportToMe')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_WORK_REPORT_USER_DETAIL,
		component:  lazy(() => import('@iso/containers/Pages/Oa/Work/UserReportDetail')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_SETTINGS_USER_RELATIONSHIP,
		component:  lazy(() => import('@iso/containers/Pages/Oa/Settings/UserRelationship')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_OA_FILE_MANAGER,
		component:  lazy(() => import('@iso/containers/Pages/Oa/File/FileManager')),
		exact: true
	},{
		path: PRIVATE_ROUTE.APP_AI_INTELLIGENT_VOICE_ASSISTANT,
		component:  lazy(() => import('@iso/containers/Pages/AI/IntelligentVoiceAssistant')),
		exact: true
	}
];

export default function AppRouter() {
	const { url } = useRouteMatch();
	return (
		<Suspense fallback={<Loader />}>
			<HashRouter history={createHashHistory()}>
			<Switch>
				{routes.map((route, idx) => (
					<Route exact={route.exact} key={idx} path={`${url}/${route.path}`}>
						<route.component />
					</Route>
				))}
			</Switch>
			</HashRouter>
		</Suspense>
	);
}
